package DB;

import java.sql.*;

//数据库连接类
public class DBConnection {
    private static final String Driver_class="com.mysql.cj.jdbc.Driver";
    private static final String url="jdbc:mysql://localhost:3306/libary?useSSL=FALSE&serverTimezone=UTC";
    private static final String user="root";
    private static final String ps="123456789";
    public static Connection getDB() throws SQLException, ClassNotFoundException {
        Class.forName(Driver_class);
        Connection connection= DriverManager.getConnection(url,user,ps);
        return connection;
    }
    public static void closeConncetion(Connection connection, PreparedStatement statement, ResultSet resultSet)
    {//静态类释放资源一定要在finally中释放
        try{
            if (connection!=null)
            {
                connection.close();
            }
            if (statement!=null)
            {
                statement.close();
            }
            if (resultSet!=null)
            {
                resultSet.close();
            }
        }catch(SQLException E)
        {E.printStackTrace();}
    }

}
